"""
HiAgent API配置文件
"""
import os
from typing import Optional

class HiAgentConfig:
    """HiAgent API配置类"""
    
    # API基础配置
    HOST = os.getenv('HIAGENT_HOST', 'agent_openapi.swjtu.edu.cn')
    PATH = '/'
    VERSION = '2023-08-01'
    SERVICE = 'app'
    REGION = 'cn-north-1'

    # IAM服务配置 (用于创建用户等操作)
    IAM_VERSION = '2024-12-25'
    IAM_SERVICE = 'iam'
    IAM_REGION = 'cn-north-1'
    
    # 认证配置 - 必须通过环境变量设置
    ACCESS_KEY = os.getenv('HIAGENT_ACCESS_KEY', '')
    SECRET_KEY = os.getenv('HIAGENT_SECRET_KEY', '')
    ACCOUNT_ID = os.getenv('HIAGENT_ACCOUNT_ID', '')

    # 工作空间配置 - 必须通过环境变量设置
    DEFAULT_WORKSPACE_ID = os.getenv('HIAGENT_WORKSPACE_ID', '')
    
    # 请求配置
    REQUEST_TIMEOUT = 30
    MAX_RETRIES = 3
    
    # 分页配置
    DEFAULT_PAGE_SIZE = 20
    MAX_PAGE_SIZE = 100

    # 默认模型配置
    DEFAULT_MODEL_ID = os.getenv('HIAGENT_DEFAULT_MODEL_ID', 'd34idr85oc9ofekvmelg')  # doubao-seed-1-6
    DEFAULT_EMBEDDING_MODEL_ID = os.getenv('HIAGENT_DEFAULT_EMBEDDING_MODEL_ID', 'd34if2o5oc9ofekvmemg')

    @classmethod
    def get_base_url(cls) -> str:
        """获取基础URL"""
        return f"https://{cls.HOST}{cls.PATH}"
    
    @classmethod
    def get_workspace_id(cls, workspace_id: Optional[str] = None) -> str:
        """获取工作空间ID"""
        return workspace_id or cls.DEFAULT_WORKSPACE_ID

    @classmethod
    def get_iam_config(cls) -> dict:
        """获取IAM服务配置 (用于创建用户等操作)"""
        return {
            'version': cls.IAM_VERSION,
            'region': cls.IAM_REGION,
            'service': cls.IAM_SERVICE
        }